package com.ht.thymeleaf.ext;

import org.thymeleaf.Arguments;
import org.thymeleaf.dom.Element;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 薄成文 13-10-24 上午10:28
 * To change this template use File | Settings | File Templates.
 */
public class BUIExtAttrProcessor extends AbstractStandardSingleAttributeModifierAttrProcessor {

    public static final String[] ATTR_NAMES =
            new String[] {
                    "data-items",
                    "data-select",
                    "data-remote"
            };

    //public static final BUIExtAttrProcessor[] PROCESSORS;

    public static final Set<IProcessor> PROCESSORS = new HashSet<IProcessor>();

    static {
        for (int i = 0; i < ATTR_NAMES.length; i++) {
            PROCESSORS.add(new BUIExtAttrProcessor(ATTR_NAMES[i]));
        }
    }

    public BUIExtAttrProcessor(String attributeName) {
        super(attributeName);
    }

    @Override
    public int getPrecedence() {
        return 11000;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    protected String getTargetAttributeName(Arguments arguments, Element element, String attributeName) {
        return attributeName;
    }

    @Override
    protected ModificationType getModificationType(Arguments arguments, Element element, String attributeName, String newAttributeName) {
        return ModificationType.SUBSTITUTION;
    }

    @Override
    protected boolean removeAttributeIfEmpty(Arguments arguments, Element element, String attributeName, String newAttributeName) {
        return true;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
